package com.css.fxfzaqbz.modules.data.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.data.entity.ExpertManagement;
import com.css.fxfzaqbz.modules.data.service.ExpertManagementService;
import com.css.fxfzaqbz.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/data/expertManagement")
@Slf4j
public class ExpertManagementController {
    @Resource
    private ExpertManagementService expertManagementService;

    //批量添加
    @PostMapping("/save/{ids}")
    public RestResponse save(@PathVariable("ids") List<String> ids) {
        RestResponse restResponse = null;
        try {
            expertManagementService.save(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("新增评审专家数据失败", e);
            restResponse = RestResponse.fail("新增评审专家数据失败!");
        }
        return restResponse;
    }

    //模糊查询加分页
    @GetMapping("/getAll")
    public RestResponse getAll(HttpServletRequest request, ExpertManagement expertManagement) {
        RestResponse restResponse = null;
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            restResponse = RestResponse.succeed(expertManagementService.getAll(curPage, pageSize, expertManagement));
        } catch (Exception e) {
            log.error("获取评审专家数据失败!", e);
            restResponse = RestResponse.fail("获取评审专家数据失败!");
        }
        return restResponse;
    }

    //批量删除
    @PostMapping("/delete/{ids}")
    public RestResponse delete(@PathVariable("ids") List<String> ids) {
        RestResponse restResponse = null;
        try {
            expertManagementService.delete(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除评审专家数据失败!", e);
            restResponse = RestResponse.fail("删除评审专家数据失败!");
        }
        return restResponse;
    }
}
